package org.example.myportfolio.dao.repository.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import lombok.extern.slf4j.Slf4j;
import org.example.myportfolio.dao.mapper.WorkMapper;
import org.example.myportfolio.pojo.param.WorksParam;
import org.example.myportfolio.pojo.po.WorkPO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.stereotype.Service;
import org.example.myportfolio.dao.repository.WorkRepository;

@Slf4j
@Repository("workRepository")
public class WorkRepositoryImpl implements WorkRepository{

    @Autowired
    private WorkMapper workMapper;


    /**
     * 日志记录时对数据进行脱敏处理
     * 避免使用BeanUtils.copyProperties() 手动赋值
     * 使用自定义异常类
     * @param worksParam
     */
    @Override
    public void updateById(WorksParam worksParam) {
        log.debug("worksParam ID:{}",worksParam.getId());
        WorkPO workPO = new WorkPO();
        // 手动复制必要的属性
        workPO.setId(worksParam.getId());
        workPO.setTitle(worksParam.getTitle());
        workPO.setDescription(worksParam.getDescription());
        try {
            workMapper.updateById(workPO);
        } catch (Exception e) {
            log.error("更新作品失败:{}",e.getMessage(),e);
            throw new RuntimeException("更新作品失败",e);
        }
    }
}
